package com.gopay.common.trace.support;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.atomic.AtomicLong;

/**
 *
 * @author ddh02
 * @GenerateTraceId
 * @2017/3/30 10:08  www.gopay.com.cn Inc.All rights reserved.
 */
@Deprecated
public class GenerateTraceId {
    private static Logger logger = LoggerFactory.getLogger(GenerateTraceId.class);
    private Long seed;
    private Long MAX_STEP = 0xffffffL;
    private AtomicLong plusId = new AtomicLong(0L);

    public GenerateTraceId(Long seed) {
        this.seed = seed;
    }

    public Long getTraceId() {
        return (seed << 40) | getPlusId();
    }


    private long getPlusId() {
        if (plusId.get() >= MAX_STEP) {
            plusId.set(0L);
        }
        return plusId.incrementAndGet();
    }

    public static void main(String[] args) {
        GenerateTraceId t = new GenerateTraceId(0L);

        for (int i = 0; i <10; i++) {

            System.out.println(t.getTraceId());
        }
    }
}
